package com.company.libraryservice.mapper;

import com.company.libraryservice.model.BorrowRecord;
import java.util.List;
import org.apache.ibatis.annotations.*;

/**
 * 借还记录数据访问接口
 *
 * @author RoyMa
 * @date 2025-08-12
 */
@Mapper
public interface BorrowRecordMapper {

  /**
   * 新增一条借/还记录
   *
   * @param record 借还记录实体
   * @return 成功插入的行数
   */
  @Insert(
      "INSERT INTO borrow_record(book_id,user_name,action,gmt_create) "
          + "VALUES(#{bookId},#{userName},#{action},NOW())")
  @Options(useGeneratedKeys = true, keyProperty = "id")
  int insert(BorrowRecord record);

  /**
   * 查询所有借还记录
   *
   * @return 借还记录列表
   */
  @Select("SELECT * FROM borrow_record ORDER BY gmt_create DESC")
  List<BorrowRecord> selectAll();
}
